 <?php

class User {
    
	private $ID_user;
	private $nama_user;
    private $alamat_user;
    private $hp;
	private $email;
	private $username;
	private $password;
	private $konfirm_password;
    

    private $Host;
    private $MySQLUsername;
    private $MySQLPassword;
    private $Database;
    private $Conn;
    

    //Constructor
    public function User()
    {
        session_start();
        $this->Host = "localhost";
        $this->MySQLUsername = "root";
        $this->MySQLPassword = "";
        $this->Database = "efutsal";

        $this->Connection();
        
        unset($this->Host);
        unset($this->MySQLUsername);
        unset($this->MySQLPassword);
        unset($this->Database);
    }


    public function Connection()
    {
        $this->Conn = @mysql_connect($this->Host,$this->MySQLUsername,$this->MySQLPassword);
        if($this->Conn)
        {
            mysql_select_db($this->Database) OR die('Could not select DB');
        }
        else
        {
            die(mysql_error());
        }  
    }
    
    public function Query($sql)
    {
        $result = mysql_query($sql); 
        if(!$result)
        {
            die(mysql_error());
        } 
        return $result;
    }
	
    
    public function Disconnect()
    {
        mysql_close($this->Conn);
    }
    
    //Escapes bad values for MySQL to prevent SQL injections.
    public function EscapeString($badstring)
    {
        if(!get_magic_quotes_gpc())
        {
            $goodstring = addslashes($badstring);
        }
        else
        {
            $goodstring = stripslashes($badstring);
        }
        $goodstring = mysql_real_escape_string($badstring);
        return $goodstring;
    }
    
	
 	public function Result_To_Array($result)
    {
        $result_array = array();

        for ($i=0; $row = mysql_fetch_array($result); $i++) 
        {
            $result_array[$i] = $row;
        }

        return $result_array;

    }
	
	
 public function AddUser($nama_user,$alamat_user,$hp,$email,$username,$password,$konfirm_password)
    {
		
		$ID = mysql_fetch_array($this->Query("SELECT MAX(ID_user)+1 from `user`"));
		$ID_user = $ID[0];
        $nama_user = $this->EscapeString($nama_user);
		$alamat_user = $this->EscapeString($alamat_user);
		$hp = $this->EscapeString($hp);
		$email = $this->EscapeString($email);
		$username = $this->EscapeString($username);
        $password = $this->EscapeString($password);
		
        $result = $this->Query("INSERT INTO `user` (ID_user,nama_user,alamat_user,hp,email,username,password) VALUES ('$ID_user','$nama_user','$alamat_user','$hp','$email','$username','$password')");
		header('location:../page/SUKSES_DAFTAR.php'); 
    }
	
	
	}